package liu.db.procedure;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import org.junit.Test;

/**
 * 调用存储过程
 * 1入参
 * 2出参
 * 
 * @author My
 *
 */
public class ProcedureTest {
	
	@Test
	public void testProcudure() throws Exception {
		//1加载驱动获得连接
		
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/szrt", "root", "root");
		
		//2把sql写出来 调用它
		String sql=" call xx_sum(?,?)";
		CallableStatement cs = conn.prepareCall(sql);
		
		//设置输入参数的值
		cs.setInt(1, 100);
		
		//注册出参
		cs.registerOutParameter(2,java.sql.Types.INTEGER);
		
		//3指定参数的值
		ResultSet rs = cs.executeQuery();
	
		//拿第二个参数的值
		int jieguo = cs.getInt(2);
		System.out.println(jieguo);
		
		
		
		//4关闭链接
		cs.close();
		conn.close();
		
		
	}

}
